package com.docking.heylo.web.controller;

import com.docking.heylo.ThreadContext;
import com.docking.heylo.constant.SystemConstant;
import com.docking.heylo.service.IMessageService;
import com.docking.heylo.utils.HeyloMessageSource;
import com.docking.heylo.web.dto.MessageDto;
import com.docking.heylo.web.utils.ResultUtil;
import com.docking.heylo.web.vo.BaseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/message")
public class UserMessageController {

    @Autowired
    private IMessageService messageService;

    @Autowired
    private HeyloMessageSource messageSource;

    /***
     * 我的消息列表
     *
     * @return
     */
    @RequestMapping("/list")
    public BaseVo my_list(@RequestBody MessageDto dto){
        dto.setUserId(ThreadContext.userId());
        return ResultUtil.success(messageSource.getMessage(SystemConstant.success), messageService.my_list(dto));
    }

    /***
     * 设置已读
     *
     * @return
     */
    @RequestMapping("/read")
    public BaseVo read(@RequestBody MessageDto dto){
        dto.setUserId(ThreadContext.userId());
        messageService.read(dto);
        return ResultUtil.success(messageSource.getMessage(SystemConstant.success));
    }








}
